home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pesquisa Dirigida
/
Pesquisa Dirigida.iso
/
JOGOS
/
parking.swf
/
scripts
/
countdownclock.as
next >
Wrap
Text File
|
2005-01-18
|
2KB
|
87 lines
function CountdownClock()
{
this.totaltime = new Number();
this.minutes = new Number();
this.seconds = new Number();
this.saveminutes = new Number();
this.saveseconds = new Number();
this.handlerObj = undefined;
this.changeHandler = new String();
}
CountdownClock.prototype = new MovieClip();
CountdownClock.prototype.setData = function(minutes, seconds, startnow)
{
this.saveminutes = minutes;
this.saveseconds = seconds;
this.minutes = minutes;
this.minutes_txt.text = "0" + this.minutes;
this.seconds = seconds;
if(this.seconds < 10)
{
this.seconds_txt.text = "0" + this.seconds;
}
else
{
this.seconds_txt.text = this.seconds;
}
this.totaltime = minutes * 60 + seconds;
if(startnow)
{
this.startCountdown();
}
};
CountdownClock.prototype.startCountdown = function()
{
this.timerID = setInterval(this,"doCountdown",1000);
};
CountdownClock.prototype.stopCountdown = function()
{
clearInterval(this.timerID);
};
CountdownClock.prototype.reset = function(startnow)
{
this.setData(this.saveminutes,this.saveseconds,startnow);
};
CountdownClock.prototype.doCountdown = function()
{
if(this.totaltime > 0)
{
this.totaltime--;
switch(true)
{
case this.seconds == 0:
this.seconds = 59;
this.seconds_txt.text = this.seconds;
this.minutes--;
this.minutes_txt.text = "0" + this.minutes;
break;
case this.seconds <= 10:
this.seconds--;
this.seconds_txt.text = "0" + this.seconds;
break;
default:
this.seconds--;
this.seconds_txt.text = this.seconds;
}
}
else
{
clearInterval(this.timerID);
this.executeCallback();
}
};
CountdownClock.prototype.setChangeHandler = function(funcname, obj)
{
this.handlerObj = obj;
this.changeHandler = funcname;
};
CountdownClock.prototype.executeCallback = function()
{
this.handlerObj[this.changeHandler](this);
};
CountdownClock.prototype.getTimeRemaining = function()
{
return this.totaltime;
};
Object.registerClass("countdownclock",CountdownClock);